package com.huawei;
import java.util.Scanner;
import java.util.Stack;

/**
 * Created by Z-hong on 2024/7/23.
 */

public class HJ70 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int count=sc.nextInt();
        int arr[][] = new int[count][2];
        for(int i=0;i<count;i++){
            arr[i][0]=sc.nextInt();
            arr[i][1]=sc.nextInt();
        }
        String str=sc.next();
        Stack<Character> stack=new Stack<>();
        Stack<Character> temp=new Stack<>();
        char[] charArray = str.toCharArray();
        int res=0;
        for (char c : charArray) {
            if(c==')'){
                char pop = stack.pop();
                while(pop!='('){
                    temp.push(pop);
                    pop = stack.pop();
                }
                while(!temp.isEmpty()){
                    char pop1 = temp.pop();
                    char pop2 = temp.pop();
                    res+= arr[pop1 - 'A'][0] * arr[pop1 - 'A'][1] * arr[pop2 - 'A'][1];
                    stack.push(pop1);
                    arr[pop1 - 'A'][1]=arr[pop2 - 'A'][1];
                }
            }else{
                stack.push(c);
            }
        }
        System.out.println(res);

    }

}
